package cn.com.zpon.shouyinyuandemo.net;

import java.util.HashMap;

import cn.com.zpon.shouyinyuandemo.net.callback.BaseCallback;
import cn.com.zpon.shouyinyuandemo.util.HttpCallback;
import cn.com.zpon.shouyinyuandemo.util.HttpUtil;

public class ServiceApi  {

    private static ServiceApi instance;
    private final static String DOMAIN="http://paydemo.17f.cn";

    public synchronized static ServiceApi getInstace() {
        if (instance == null) {
            instance = new ServiceApi();
        }
        return instance;
    }

    /**
     * 获取支付订单信息
     * @param channel  支付类型 wx:微信 alipay:支付宝
     * @param amount   支付金额(单位分)
     * @param subject 购买的商品名
     * @param callback
     */
    public void fetchOrderInfo(String channel, int amount, String subject,final BaseCallback callback){

        HashMap<String,String> params = new HashMap<>();
        params.put("channel",channel);
        params.put("amount",amount+"");
        params.put("subject",subject);

        HttpUtil.post(DOMAIN + "/api/pay",params, new HttpCallback() {
            @Override
            public void onFinished(String result) {
                if (result==null){
                    callback.requestFail("获取订单信息失败");
                }else{
                    callback.requestSuccess(result);
                }
            }
        });

    }
}
